<template>
  <div class="usercenter">
    <!-- 导航条 -->
    <van-nav-bar title="用户中心" left-arrow :fixed="true" :border="true" @click-left="$router.back()" />
    <div class="logout">
      <button @click.prevent="logOut">退出登录</button>
    </div>
  </div>
</template>


<script>
import { getLogOut } from "./../../../service/api/index";
import { mapMutations } from "vuex";
import { Toast } from "vant";
export default {
  name: "userCenter",

  data() {
    return {};
  },
  methods: {
    ...mapMutations(["RESET_USER_INFO", "CLEAR_CART"]),
    async logOut() {
      let result = await getLogOut();
      if (result.success_code === 200) {
        // 清空本地的数据
        this.RESET_USER_INFO();
        //清空本地购物车
        this.CLEAR_CART();
        Toast({
          message: "退出登录成功!",
          duration: 500
        });
      }
    }
  }
};
</script>


<style lang="less" scoped>
.usercenter {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #f5f5f5;
  z-index: 222;

  .logout {
    position: fixed;
    margin-top: 20rem;
    width: 80%;
    height: 38px;
    background-color: #2eba5a;
    font-size: 20px;
    border: none;
    border-radius: 5px;
    color: #fff;
    text-align: center;
    line-height: 38px;
    transform: translateX(13%);

    button {
      background-color: transparent;
    }
  }
}
</style>